import request from "../util/request"
import userstore from '@/store/user.js'
const api={
	wxlogin:"/login/wx",//微信登录
	sendphoneyzm:'/login/sendphoneyzm',//发送手机验证码
	pdphoneyzm:'/login/pdphoneyzm',//判断验证码,
	adduser:"/login/adduser",//添加用户，
	phonelogin:'/login/phonelogin',//手机账号登录，
	ishasphone:"/login/ishasphone",//手机号是否存在
	updatepassword:'/login/updatepassword',
	getbanderdata:"/main/bander",//获取轮播
    updateimg:"/user/updataimg",//更改头像
	updatename:"/user/updataname",//更换姓名
	getsylx:"/lx/getall",//获得商品类型
	getshopper:'/client/getshopper',//获得商品商家
	getproducts:"/clipro/getpro",//获得商品
	getproductxq:"/client/shoper/",//获得商品详情
	seachpro:"/clipro/seach",//搜索
	lxproduc:'/clipro/lx',//获取类型商品
	setloves:"/loves/setloves",//添加喜欢
	delloves:"/loves/dleloves",//删除喜欢
	islovess:"/loves/isloves",//是否喜欢,
	getlovesdata:"/loves/getloves",
	addorder:'/order/add',
	getorder:'/order/get',
	getbyid:'/clipro/getbyid',
	setorderstatus:'/order/set'
}
export const getupdatepassword=(data)=>request({url:api.updatepassword,data:{...data},method:"post"})
export const getwxlogin=(data)=>request({url:api.wxlogin,data:{...data},method:"post"})
export const getpdphoneyzm=(data)=>request({url:api.pdphoneyzm,data:{...data},method:"post"})
export const getadduser=(data)=>request({url:api.adduser,data:{...data},method:"post"})
export const getsendphoneyzm=(phone)=>request({url:api.sendphoneyzm,data:{phone}})
export const getishasphone=(phone)=>request({url:api.ishasphone,data:{phone}})
export const getphonelogin=(data)=>request({url:api.phonelogin,data:{...data}})
export const getgetbanderdata=(data)=>request({url:api.getbanderdata})
export const supdateimg=(id,path)=>{
	return new Promise((res,rej)=>{
		const useuserstore=userstore()
		  uni.uploadFile({
			  url:'http://127.0.0.1:3006'+api.updateimg,
			  header:{
				  token:useuserstore.token
			  },
			filePath:path,
			name:'userimg',
			formData:{
				id
			},
			success(e) {
				res(JSON.parse(e.data))
			}
			,fail(e) {
				console.log(e)
			}
		  })
	})
}
export const supdatename=(id,name)=>request({url:api.updatename,data:{id,name},method:"post"})
export const getlx=()=>request({url:api.getsylx})
export const sgetshopper=(address)=>request({url:api.getshopper,data:{address}})
export const sgetproducts=(address,offset,limit)=>request({url:api.getproducts,data:{address,offset,limit},method:"post"})
export const sgetproductxq=(id)=>request({url:api.getproductxq+id})
export const sseachpro=(seachdata,limit,offset)=>request({url:api.seachpro,data:{seachdata,limit,offset},method:"post"})
export const sslxproduc=(address,limit,offset,lx)=>request({url:api.lxproduc,data:{address,limit,offset,lx},method:"post"})
export const setlovess=(userid, productid)=>request({url:api.setloves,data:{userid, productid}})
export const dellovess=(userid, productid)=>request({url:api.delloves,data:{userid, productid}})
export const islovesss=(userid, productid)=>request({url:api.islovess,data:{userid, productid}})
export const getlovesdatass=(userid,limit, offset)=>request({url:api.getlovesdata,data:{userid,limit, offset}})
export const addorders=(data)=>request({url:api.addorder,data,method:'post'})
export const getorders=(data)=>request({url:api.getorder,data,method:'post'})
export const getbyids=(data)=>request({url:api.getbyid,data,method:'post'})
export const ssetorderstatus=(data)=>request({url:api.setorderstatus,data,method:'post'})
